// using UnityEngine;
// using System.Collections.Generic;
// using Newtonsoft.Json;
// using System.IO;
// using ICSharpCode.SharpZipLib.Zip;
// using System.Net;
// //using EvonyExtension;
// using Frankfort.Threading.Internal;
// using System.Threading;


// public class DecompressLocalBundleHelper: Singleton<DecompressLocalBundleHelper>
// {
// 	public delegate void DecompressBundleCallBack(bool success);
// 	private static string apkPath;
	
// 	private Dictionary<string, KeyValuePair<BundleInfo, HashSet<DecompressBundleCallBack>>> waitingTask = null;
// 	private LinkedList<Dictionary<string, KeyValuePair<BundleInfo, HashSet<DecompressBundleCallBack>>>> runningTask = new LinkedList<Dictionary<string, KeyValuePair<BundleInfo, HashSet<DecompressBundleCallBack>>>>();
	
// 	public DecompressLocalBundleHelper()
// 	{
// 		apkPath = Application.dataPath;
// 		//		apkPath = Application.streamingAssetsPath + "/" + "a.apk";
// 	}
	
// 	public void Cancel(string bundleName, BundleInfo info, DecompressBundleCallBack callBack)
// 	{
// 		KeyValuePair<BundleInfo, HashSet<DecompressBundleCallBack>> temp = new KeyValuePair<BundleInfo, HashSet<DecompressBundleCallBack>>();
// 		LinkedList<Dictionary<string, KeyValuePair<BundleInfo, HashSet<DecompressBundleCallBack>>>>.Enumerator e = runningTask.GetEnumerator();
// 		while(e.MoveNext())
// 		{
// 			if(e.Current.TryGetValue(bundleName, out temp))
// 			{
// 				temp.Value.Remove(callBack);
// 				return;
// 			}
// 		}
		
// 		if(waitingTask != null)
// 		{
// 			if(waitingTask.TryGetValue(bundleName, out temp))
// 			{
// 				temp.Value.Remove(callBack);
// 			}
// 		}
// 	}
	
// 	private void DecompressBundles (Dictionary<string, KeyValuePair<BundleInfo, HashSet<DecompressBundleCallBack>>> needDecompressBundles)
// 	{
// 		SingleThreadStarter.StartSingleThread (() =>  {
// 			bool ret = DecompressOrDeleteLocalBundle2 (needDecompressBundles);
// 			Finish(ret, needDecompressBundles);
// 		});
// 	}
	
// 	private void Finish(bool success, Dictionary<string, KeyValuePair<BundleInfo, HashSet<DecompressBundleCallBack>>> needDecompressBundles)
// 	{
// 		if(!Loom.CheckIfMainThread())
// 		{
// 			MainThreadDispatcher.DispatchToMainThread((object obj) => 
// 			                                          {
// 				Finish(success, needDecompressBundles);
// 			}, null);
// 			return;
// 		}
		
// 		runningTask.Remove(needDecompressBundles);
		
// 		Dictionary<string, KeyValuePair<BundleInfo, HashSet<DecompressBundleCallBack>>>.Enumerator e = needDecompressBundles.GetEnumerator();
// 		while(e.MoveNext())
// 		{
// 			HashSet<DecompressBundleCallBack>.Enumerator e2 = e.Current.Value.Value.GetEnumerator();
// 			while(e2.MoveNext())
// 			{
// 				e2.Current(success);
// 			}
// 		}
// 	}
	
// 	public void DecompressBundle(string bundleName, BundleInfo info, DecompressBundleCallBack callBack)
// 	{
// 		KeyValuePair<BundleInfo, HashSet<DecompressBundleCallBack>> temp = new KeyValuePair<BundleInfo, HashSet<DecompressBundleCallBack>>();
// 		LinkedList<Dictionary<string, KeyValuePair<BundleInfo, HashSet<DecompressBundleCallBack>>>>.Enumerator e = runningTask.GetEnumerator();
// 		while(e.MoveNext())
// 		{
// 			if(e.Current.TryGetValue(bundleName, out temp))
// 			{
// 				temp.Value.Add(callBack);
// 				return;
// 			}
// 		}
		
// 		if(waitingTask == null)
// 		{
// 			waitingTask = new Dictionary<string, KeyValuePair<BundleInfo, HashSet<DecompressBundleCallBack>>>();
// 		}
		
// 		if(!waitingTask.TryGetValue(bundleName, out temp))
// 		{
// 			temp = new KeyValuePair<BundleInfo, HashSet<DecompressBundleCallBack>>(info, new HashSet<DecompressBundleCallBack>());
// 			waitingTask.Add(bundleName, temp);
// 		}
		
// 		temp.Value.Add(callBack);
// 	}
	
// 	public void startDecompress()
// 	{
// 		if(waitingTask != null && waitingTask.Count > 0)
// 		{
// 			runningTask.AddLast(waitingTask);
// 			DecompressBundles(waitingTask);
// 			waitingTask = null;
// 		}
// 	}
	
// 	private bool DecompressOrDeleteLocalBundle2(Dictionary<string, KeyValuePair<BundleInfo, HashSet<DecompressBundleCallBack>>> needDecompressBundles)
// 	{
// 		if(Application.platform == RuntimePlatform.IPhonePlayer)
// 		{
// 			Dictionary<string, KeyValuePair<BundleInfo, HashSet<DecompressBundleCallBack>>>.Enumerator e = needDecompressBundles.GetEnumerator();
// 			while(e.MoveNext())
// 			{
// 				string bundleName = e.Current.Key;

//                 string realBundleName = e.Current.Value.Key.GetHashName() + BundleVersionManager.bundleExt2;
// 				string outputPath = BundleVersionManager.bundlePath + "/" + realBundleName;

// 				CommonUtil.Delete(outputPath);
// 			}
			
// 			return true;
// 		}
// 		else
// 		{
// 			Dictionary<string, KeyValuePair<string, KeyValuePair<BundleInfo, HashSet<DecompressBundleCallBack>>>> newDic = new Dictionary<string, KeyValuePair<string, KeyValuePair<BundleInfo, HashSet<DecompressBundleCallBack>>>>();
// 			Dictionary<string, KeyValuePair<BundleInfo, HashSet<DecompressBundleCallBack>>>.Enumerator e = needDecompressBundles.GetEnumerator();
// 			while(e.MoveNext())
// 			{
// 				string bundleName = e.Current.Key;
// 				string realBundleName = bundleName + BundleVersionManager.bundleExt2;
// 				string entryName = "assets/" + realBundleName;
// 				newDic.Add(entryName, e.Current);
// 			}
			
// 			if(!System.IO.File.Exists(apkPath))
// 			{
// 				return false;
// 			}
			
// 			bool globalRet = true;
// 			FileStream input = null;
// 			ZipInputStream zipInput = null;
// 			try
// 			{
// 				input = File.OpenRead(apkPath);
// 				zipInput = new ZipInputStream(input);
// 				while(true)
// 				{
// 					ZipEntry entry = zipInput.GetNextEntry();
// 					if(entry == null)
// 					{
// 						break;
// 					}
					
// 					KeyValuePair<string, KeyValuePair<BundleInfo, HashSet<DecompressBundleCallBack>>> temp = new KeyValuePair<string, KeyValuePair<BundleInfo, HashSet<DecompressBundleCallBack>>>();
// 					if(newDic.TryGetValue(entry.Name, out temp))
// 					{
// 						string bundleName = temp.Key;
//                         string realBundleName = temp.Value.Key.GetHashName() + BundleVersionManager.bundleExt2;
// 						string outputPath = BundleVersionManager.bundlePath + "/" + realBundleName;
						
// 						bool ret = false;
// 						if(globalRet)
// 						{
// 							CommonUtil.Delete(outputPath);

// 							ret = CompressManager.DecompressStreamToFile(BundleVersionManager.instance.GetBundleVersionConfig().compress, zipInput, outputPath);
							
// 							globalRet = ret;
// 						}
						
// 						myDecompressCallBack(bundleName, ret, temp.Value.Value);
// 					}
// 				}
// 			}
// 			catch(System.Exception e2)
// 			{
// 				Debug.LogException(e2);
// 			}
// 			finally
// 			{
// 				if(zipInput != null)
// 				{
// 					zipInput.Close();
// 					zipInput = null;
// 				}
// 			}
			
// 			return globalRet;
// 		}
// 	}



	
// 	private void myDecompressCallBack(string bundleName, bool success, HashSet<DecompressBundleCallBack> callBacks)
// 	{
// 		if(!Loom.CheckIfMainThread())
// 		{
// 			MainThreadDispatcher.DispatchToMainThread((object obj)=>
// 			                                          {
// 				myDecompressCallBack(bundleName, success, callBacks);
// 			}, null);
// 			return;
// 		}
		
// 		HashSet<DecompressBundleCallBack> temp = new HashSet<DecompressBundleCallBack>(callBacks);
// 		callBacks.Clear();
		
// 		HashSet<DecompressBundleCallBack>.Enumerator e2 = temp.GetEnumerator();
// 		while(e2.MoveNext())
// 		{
// 			e2.Current(success);
// 		}
// 	}
// }

